<?php

/**
 * Fixes a comparrison bug in the ZendX decorator code ...
 * The problem is on line 74 of ZendX_JQuery_Form_Decorator_UiWidgetElement
 * 
 * As long as we don't change the framework to a newer version this will do.
 * 
 * @author udsholt
 *
 */
class Pldkp_Form_Decorator_UiWidgetElementFix extends ZendX_JQuery_Form_Decorator_UiWidgetElement
{
    /**
     * Overide for the bugged function
     *
     * @return array
     */
    public function getElementAttribs() 
    {
        return;
        if (null === $this->_attribs) {
            if($this->_attribs = $this->_getElementAttribs()) {
                if (array_key_exists('jQueryParams', $this->_attribs)) {
                    $this->setJQueryParams($this->_attribs['jQueryParams']);
                    unset($this->_attribs['jQueryParams']);
                }
            }
        }

        return $this->_attribs;
    }
    
    /**
     * this is copied from Zend_Form_Decorator_ViewHelper
     * Php has no means of calling a method on a parent parents ... wonderful really
     * 
     * @return array
     */
    private function _getElementAttribs()
    {
        if (null === ($element = $this->getElement())) {
            return null;
        }

        $attribs = $element->getAttribs();
        if (isset($attribs['helper'])) {
            unset($attribs['helper']);
        }

        if (method_exists($element, 'getSeparator')) {
            if (null !== ($listsep = $element->getSeparator())) {
                $attribs['listsep'] = $listsep;
            }
        }

        if (isset($attribs['id'])) {
            return $attribs;
        }

        $id = $element->getName();

        if ($element instanceof Zend_Form_Element) {
            if (null !== ($belongsTo = $element->getBelongsTo())) {
                $belongsTo = preg_replace('/\[([^\]]+)\]/', '-$1', $belongsTo);
                $id = $belongsTo . '-' . $id;
            }
        }

        $element->setAttrib('id', $id);
        $attribs['id'] = $id;

        return $attribs;
    }
}